package dataStructures;

import java.rmi.MarshalledObject;
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

/**
 * Created with IntelliJ IDEA.
 * User: Vikas.Bhardwaj
 * Date: 5/22/12
 * Time: 11:30 AM
 * Tree Map which sorts by value
 *
 */
public class ModifiedComparator implements Comparator  {


    @Override
    public int compare(Object o1, Object o2) {
        return compare((Map.Entry) o1, (Map.Entry) o2);
    }

    public int compare(Map.Entry e1, Map.Entry e2){

        int cf = ((Comparable)e1.getValue()).compareTo(e2.getValue());
        if (cf == 0) {
            cf = ((Comparable)e1.getKey()).compareTo(e2.getKey());
        }
        return cf;
    }
}
